<script>
    $(document).ready(function(){
        $("#newCustomerForm").validate({
            rules: {
			    studentid: "required",
			    first_name: "required",
			    last_name: "required",
			    phone: {
    			     number: true,
    			     minlength: 10,
    			     maxlength: 10
                },
          email: "email"

			    username: {
				    required: true,
				    minlength: 2
			    },
			    password: {
				    required: true,
				    minlength: 5
			    },
			    password_confirmation: {
				    required: true,
				    minlength: 5,
				    equalTo: "#password"
			    },
			    }
        });
  });
</script>
<div style="line-height: 22px;">
<%= error_messages_for 'customer' %>
<% form_remote_tag :url => {:controller => "customer", :action=> "add_customer"}, :html => {:id => "newCustomerForm"} do %>
    <table style="margin: auto;">
        <tr>
            <td style="width: 80px;" valign="top">
                Student ID:
            </td>
            <td>
	            <%= text_field_tag :studentid, params[:studentid], :size => 25 %>
            </td>
        </tr>
        <tr>
            <td style="width: 80px;" valign="top">
              First Name:
            </td>
            <td>
	            <%= text_field_tag :first_name, params[:first_name], :size => 25 %>
            </td>
        </tr>
        <tr>
            <td style="width: 80px;" valign="top">
              Last Name:
            </td>
            <td>
	            <%= text_field_tag :last_name, params[:last_name], :size => 25 %>
            </td>
        </tr>
        <tr>
            <td valign="top">
        	    Phone:
	        </td>
	        <td>
	            <%= text_field_tag :phone, params[:phone], :size => 25 %>
            </td>
        </tr>
        <tr>
            <td valign="top">
        	    Email:
	        </td>
	        <td>
        	    <%= text_field_tag :email, params[:email], :size => 25 %>
            </td>
        </tr>
        <tr>
            <td>
                Other Info:
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <%= text_area_tag :other_info, params[:other_info], :cols => 37, :rows => 4 %>
            </td>
        </tr>
    </table>
    <%= submit_tag "Save", :class => "submit", :post => "true" %>| <input type="submit" value="Real Save">
    <blink><span style="color: red; font-size: 1.4em;">These save buttons are saving twice :(</blink>
    <% end %>
</div>

<script type="text/javascript">
$(function() {
    $('#studentid').focus();
});

    $("form").submit(function() {
      //$.post(this.action, $(this).serialize(), null, "script");
      $.post(this.action, $(this).serialize(), null, "script");
      //$.post(<%= escape_javascript(render(:action => 'add_customer')) %>, $(this).serialize(), null, "script");
      $('#display-name').val($('#studentid').val());
      $('#add_customer_dialog').dialog('close');
      return false;
    });
</script>

